package com.mikelouis.test.scala.proginscala.chapter3



/**
 * Created by yuazhu on 12/18/2014.
 */
object setAndMap {
  def main(args: Array[String]) {
    /** Set */
    println("***************Set***************")
    // a immutable Set will be created: scala.collection.mutable.Set
    // if no package specified, a immutable version will be created
    var jetSet = scala.collection.immutable.Set("Boeing", "Airbus")
    jetSet += "Lear"
    println(jetSet)

    // if need a mutable set to be created, need to import the class first
    val movieSet = scala.collection.mutable.Set("Hitch", "Poltergeist")
    movieSet += "Shrek"
    println(movieSet)

    // create an immutable HashSet
    val hashSet = scala.collection.immutable.HashSet("Tomatoes", "Chilies")
    println(hashSet + "Coriander")


    /** Map */
    println("***************Map***************")
    // immutable map: if no package specified, scala.collection.immutable.Map by default
    val romanNumeral = Map( 1 -> "I", 2 -> "II", 3 -> "III", 4 -> "IV", 5 -> "V" )
    println(romanNumeral(4))

    // mutable map
    // 显式类型参数化，“[Int, String]”，对代码来说是必须的，因为没有任何值被传递给工厂方法, 编译器无法推断映射的类型参数
    val treasureMap = scala.collection.mutable.Map[Int, String]()
    treasureMap += (1 -> "Go to island.")
    treasureMap += (2 -> "Find big X on ground.")
    treasureMap += (3 -> "Dig.")
    println(treasureMap)
  }
}
